var app = angular.module(setting.appName);
app.register.controller("RechargeUsExchangeCtrl", ["$rootScope", "$scope", "$location", "$timeout", "$window", "ToastMessage", "SecurityService", "FundService", "StockService", function($rootScope, $scope, $location, $timeout, $window, ToastMessage, SecurityService, FundService, StockService) {
    $scope.sourceAvailableMoney = "",
    $scope.$watch("sourceMoney", function(newValue, oldValue) {
        newValue && (newValue > $scope.sourceAvailableMoney ? $scope.sourceMoney = $scope.sourceAvailableMoney : $scope.targetMoney = Calc.DivDown(newValue, $scope.rate, 2))
    }),
    $scope.showPop = function() {
        $scope.showConfirm = !0,
        $("#sourceMoney").blur(),
        $timeout(function() {
            $("#password").focus()
        }, 10)
    }
    ,
    $scope.doExchange = function(event) {
        app.util.setDisabled(event.target),
        app.util.loading(event.target, !0);
        var params = {
            sourceType: "HKD",
            money: $scope.sourceMoney,
            targetMoney: $scope.targetMoney,
            password: $scope.password,
            targetType: "USD"
        };
        FundService.rechargeByExchange(params).success(function(data) {
            ToastMessage.show(data.message, data.success),
            data && data.success && ($scope.exchangeSuccess = !0),
            app.util.setEnabled(event.target),
            app.util.loading(event.target, !1)
        })
    }
    ;
    var funs = {
        loadSummary: function() {
            FundService.queryAccountSummary("HKD").success(function(data) {
                data && data.success && ($scope.sourceAvailableMoney = data.result.availableMoney)
            })
        },
        loadRate: function() {
            FundService.getExchangeRate("HKD", null , "USD").success(function(data) {
                data && data.success && ($scope.rate = data.result)
            })
        }
    };
    funs.loadSummary(),
    funs.loadRate()
}
]);
